
import pymongo
from config import *

class MongoClient():

    name = "user"

    def __init__(self):

        self.client = pymongo.MongoClient( mongo["mongo_uri"])
        self.db = self.client[MongoClient.name]

    def saveMongo(self,data):

        try:
            self.db['user'].update({'user_id': data['user_id']}, {'$set': data}, True)

            print("数据存储MongoDB成功:",data["nickname"])

        except:

            print("数据存储MongoDB失败:", data["nickname"])


if __name__ == '__main__':

    mongo = MongoClient()

    data = {

        "title": "奉天小馆",
        "star": "四星饭店",
        "pubCom": "80",

    }

    mongo.saveMongo( data )
